// Dynamic Proxy by Lukasz Kwiecinski, Poznan, 2004
// Author: grosee@wp.pl
// You may use this code without any prohibition.

using System;
using System.Reflection;

namespace GURUCORE.Framework.Core.Proxy
{
	/// <summary>
	/// Allows adding special functionality to selected methods of wrapped object.
	/// </summary>
    [System.Diagnostics.DebuggerStepThrough]
	public abstract class MethodInvocationBase : IMethodInvocation
	{
		private string m_sModuleID;
		public string ModuleID
		{
			set
			{
				m_sModuleID = value;
			}
			get
			{
				return m_sModuleID;
			}
		}
		/// <summary>
		/// Called by proxy just before the wrapped object's method
		/// calling.
		/// </summary>
		/// <param name="target">Wrapped object for which the method will be called.</param>
		protected abstract void OnMethodCalling(object target, MethodInfo p_oCallingMethod);

		/// <summary>
		/// Called by proxy just after control returns from wrapped
		/// object's method and there were no exception thrown from
		/// within the method.
		/// </summary>
		/// <param name="target">Wrapped object which method returned successfully.</param>
		protected abstract void OnMethodCallSuccess(object target, MethodInfo p_oCallingMethod);

		/// <summary>
		/// Called by proxy just after control leaves wrapped
		/// object's method because of an exception occurence.
		/// </summary>
		/// <param name="target">Wrapped object for which the method failed.</param>
		/// <param name="exception">Exception which was thrown from within wrapped method.</param>
		protected abstract void OnMethodCallFailure(object target, MethodInfo p_oCallingMethod, Exception exception);

		/// <summary>
		/// Called by proxy just after control leaves wrapper method
		/// This method is always called from finally block after <see cref="OnMethodCallSuccess"/> or
		/// <see cref="OnMethodCallFailure"/>.
		/// </summary>
		/// <param name="target">Wrapped object which method returned successfully or through an
		/// exception.</param>
		protected abstract void OnMethodReturned(object target, MethodInfo p_oCallingMethod);



		#region IMethodExecutionController implementation

        /// #$$$$$$$$$$$$$$$$$$$$$$$$$$$<summary>
        /// NOTE: these function is hide from Debugger
        /// $$$$$$$$$$$$$$$$$$$$$$$$$$$$</summary>
              


        [System.Diagnostics.DebuggerHiddenAttribute()]
		void IMethodInvocation.OnMethodCalling(object target, MethodInfo p_oCallingMethod)
		{
			OnMethodCalling(target,p_oCallingMethod);
		}

        [System.Diagnostics.DebuggerHiddenAttribute()]
		void IMethodInvocation.OnMethodCallSuccess(object target, MethodInfo p_oCallingMethod)
		{
			OnMethodCallSuccess(target, p_oCallingMethod);
		}

        [System.Diagnostics.DebuggerHiddenAttribute()]
		void IMethodInvocation.OnMethodCallFailure(object target, MethodInfo p_oCallingMethod, Exception exception)
		{
			OnMethodCallFailure(target, p_oCallingMethod, exception);
		}

        [System.Diagnostics.DebuggerHiddenAttribute()]
		void IMethodInvocation.OnMethodReturned(object target, MethodInfo p_oCallingMethod)
		{
			OnMethodReturned(target, p_oCallingMethod);
		}

		#endregion

		/// <summary>
		/// Creates an instance of the controller.
		/// </summary>
		protected MethodInvocationBase()
		{
		}
	}
}